package com.example.xj.storm.topologys;

import com.example.xj.storm.bolt.HelloWorldBolt;
import com.example.xj.storm.spouts.HelloWorldSpout;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.topology.TopologyBuilder;

/**
 * Created by Administrator on 2018/9/6.
 */
public class HelloWorldTopologys {

    private static final String str1="spout1";
    private static final String str2="bolt1";

    /**
     * 创建topologys
     */
    public void createTopology(){

        TopologyBuilder builder=new TopologyBuilder();
        builder.setSpout(str1, new HelloWorldSpout());
        builder.setBolt(str2, new HelloWorldBolt(),1).setNumTasks(1).localOrShuffleGrouping(str1);

        //数据源,map格式
        Config conf = new Config();
        conf.put("xiongjie", "hexingjie");
        try{

            //启动远程模式
//            System.out.println("远程模式");
//            StormSubmitter.submitTopology("remote", conf, builder.createTopology());

            //启动本地模式
            System.out.println("本地模式");
            LocalCluster cluster = new LocalCluster();
            cluster.submitTopology("local" ,conf,  builder.createTopology() );

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
